﻿#ifndef TRCHARTKGRIDS_H
#define TRCHARTKGRIDS_H

#include <QDebug>
#include <QWidget>
#include <QDateTime>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include "TrQuoteData.h"
#include "TrChartTopBar.h"
#include "TrChartMainArea.h"


class TrChartKGrids : public QWidget
{
    Q_OBJECT
public:
    explicit TrChartKGrids(QWidget *parent = nullptr);
    ~TrChartKGrids();
    void setCode(const QString& code, const QString& name, double priceTick, int scale);

    void virtual paintEvent(QPaintEvent* event);

    /*
    K线最大显示数量
    pos 为每个K线所占用的像素,包含间距
    */
    int getMaxKlineCount(int pos = 4);
protected:
    void initLayouts();
private:
    QString             m_stCode;
    QString             m_stName;
    double              m_dPriceTick        = 0.00;
    int                 m_iVolScale         = 0;
    TrQuoteData *       m_pQuoteData        = nullptr;
    TrChartTopBar *     m_pChartTopBar      = nullptr;
    TrChartMainArea *   m_pChartMainArea    = nullptr;
    TrKlinePeriod       m_iPeriod;

    std::vector<double>     m_vdOpen;
    std::vector<double>     m_vdHigh;
    std::vector<double>     m_vdLow;
    std::vector<double>     m_vdClose;
    std::vector<int>        m_viVolume;
    std::vector<QDateTime>      m_viDatetime;
    std::vector<WTSBarStruct>   m_vKlineDatas;

    double              m_dmaxPrice = 0;
    double              m_dminPrice = 0;

    void clearData();

signals:

public slots:
    void OnQuote(QJsonArray json);
    void OnPeriodChange(TrKlinePeriod period);

};

#endif // TRCHARTKGRIDS_H
